package com.manli.api.service;

import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.List;
import com.manli.api.pojo.Result;
import com.manli.api.util.ResultUtil;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import com.manli.api.dao.UserRoleDao;
import com.manli.api.dto.UserRole;
import org.springframework.transaction.annotation.Transactional;


@Service("userRoleService")
public class UserRoleService {
    @Autowired
    UserRoleDao userRoleDao;

    
    public Result queryPage(Map<String, Object> params) {
        PageQuery<UserRole> page = userRoleDao.createQuery()
                .page(Long.parseLong(params.get("page").toString()),Long.parseLong(params.get("limit").toString()));
        return ResultUtil.success(page.getList(),page.getTotalRow());
    }

    
    public Result queryAll() {
        List<UserRole> list = userRoleDao.all();
        return ResultUtil.success(list);
    }

    
    public Result getById(Integer userId) {
        UserRole userRole = userRoleDao.single(userId);
        return ResultUtil.success(userRole);
    }

    @Transactional
    public Result save(UserRole userRole) {
        userRoleDao.insert(userRole);
        return ResultUtil.success();
    }

    @Transactional
    public Result updateById(UserRole userRole) {
        userRoleDao.updateTemplateById(userRole);
        return ResultUtil.success();
    }

    @Transactional
    public Result removeById(Integer userId) {
        userRoleDao.deleteById(userId);
        return ResultUtil.success();
    }

    @Transactional
    public Result removeByIds(List<Integer> ids) {
        for (Integer id:ids) {
            userRoleDao.deleteById(id);
        }
        return ResultUtil.success();
    }



}
